package com.wondersgroup.fjzlpt.org.service.impl.zy;

import java.util.Map;

import com.quick.framework.exception.ServiceException;
import com.quick.framework.util.LoggerUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.quick.framework.boot.remoteResult.ResultObject;
import com.wondersgroup.fjzlpt.org.dao.inter.zy.ZyDAO;
import com.wondersgroup.fjzlpt.org.service.inter.zy.ZyService;

@Service
public class ZyServiceImpl implements ZyService{

	@Autowired
	private ZyDAO zyDao;

	/**
	 * 查询表数据
	 * @param map
	 * @return JSONArray
	 */
	public JSONArray queryTable(Map<String, String> map) {
		return zyDao.queryTable(map);
	}

	/**
	 * 分页查询表数据
	 * @param map
	 * @return JSONArray
	 */
	public JSONObject queryPageTable(Map<String, String> map) {
		return zyDao.queryPageTable(map);
	}

	/**
	 * 删除表数据
	 * @param map
	 * @return
	 */
	public JSONObject delete(Map<String, String> map) {
		ResultObject ro = new ResultObject();
		try {
			zyDao.deleteOne(map);
		} catch (Exception e) {
			LoggerUtil.error(e.getMessage());
			throw new ServiceException("ERR-001101","删除字典表" + map.get("TABLENAME") + "失败！");
		}
		return (JSONObject)JSON.toJSON(ro);
	}

	/**
	 * 新增表数据
	 * @param map
	 * @return
	 */
	public JSONObject insert(Map<String, String> map) {
		ResultObject ro = new ResultObject();
		try {
			zyDao.insertOne(map);
		} catch (Exception e) {
			LoggerUtil.error(e.getMessage());
			throw new ServiceException("ERR-001102","新增字典表" + map.get("TABLENAME") + "失败！");
		}
		return (JSONObject)JSON.toJSON(ro);
	}

	/**
	 * 更新表数据
	 * @param map
	 * @return
	 */
	public JSONObject update(Map<String, String> map) {
		ResultObject ro = new ResultObject();
		try {
			zyDao.updateOne(map);
		} catch (Exception e) {
			LoggerUtil.error(e.getMessage());
			throw new ServiceException("ERR-001103","更新字典表" + map.get("TABLENAME") + "失败！");
		}
		return (JSONObject)JSON.toJSON(ro);
	}
	

	
}




















